// packageG/mycomponent/lawyer/lawyer.js
var location = require("../../../mybehaviors/location/location");
var app = getApp()
Component({
  behaviors: [location],
  /**
   * 组件的属性列表
   */
  properties: {
    datas: {
      type: null
    },
    component_id: {
      type: null
    },
    page_id: {
      type: null
    }
  },
  lifetimes: {
    attached() {
      this.initData()
      
      this._getLocation((res) => {
        this.get_lawyer_list()
      },(err)=>{
        //拒绝定位
      });

      // this.initData()
      // let point = wx.getStorageSync('address-point').point;
      // if(this.data.point && this.data.point.lng !== point.lng){
      //   this.setData({point})
      //   //定位发生变化重新请求
      //   this.get_lawyer_list()
      // }
    }
  },
  data: {
    listData: [],
    // point:{}
  },
  methods: {
    get_lawyer_list(){
      app._postNetWork({
        url: app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.lawyer.getLawyerList"),
        data: {
          lng:this.data.point.lng,
          lat:this.data.point.lat,
          distance_type:1,
          decorate_total:this.data.datas.get_number
        },
        success: res => {
          if (res.data.result == 1) {
            let arr = res.data.data.list;
            this.setData({
              listData:arr
            })
          }
        }
      })
    },
    initData() {
      let {get_number,list} = this.data.datas;
      if (get_number && list && list.length!==0) {
        this.data.listData = list.slice(0, get_number);
        this.setData({listData: this.data.listData})
      }
    },
    to(e) {
      let type = e.currentTarget.dataset.type,
      id=e.currentTarget.dataset.id;
      wx.navigateTo({
        url: `/packageI/lawyerPlatform/detail/detail?id=${id}&type_name=${type}`
      })
    }
  }
})